package com.example.siyun.controller.courseauditcontroller;

import com.example.siyun.pojo.CourseAudit;
import com.example.siyun.service.impl.courseauitserviceimpl.CourseAuitServiceImpl;
import com.example.siyun.util.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @Auther: 全
 * @Date: 2022/9/26 09:33
 * @Description:教师模块课程核查
 */
@Slf4j
@RestController
public class CourseProcessController {
    @Autowired
    private CourseAuitServiceImpl courseAuitService;
    /**
     * 添加课程核查信息
     * @param courseAudit 要添加的客户核查信息
     */
    @RequestMapping("/primary/addcourseprocess")
    public PageResult addCourseProcess(CourseAudit courseAudit, HttpSession session){
        log.info("添加的客户核查信息");
        Timestamp time = new Timestamp(new Date().getTime());
        courseAudit.setAudittime(time);
        String auditname = (String) session.getAttribute("loginname");
        courseAudit.setAuditors(auditname);
        if(courseAudit.getAuditresults().equals("审核通过")){
            int shstatus=1;
            courseAuitService.courseAuditAdd(courseAudit);
            courseAuitService.courseAuditStatus(shstatus,courseAudit.getAid());
        } else if (courseAudit.getAuditresults().equals("审核不通过")) {
            int shstatus=2;
            courseAuitService.courseAuditStatus(shstatus,courseAudit.getAid());
            courseAuitService.courseAuditAdd(courseAudit);
        }
        log.info("添加的客户核查信息成功");
        PageResult pageResult=new PageResult();
//        pageResult.setStatus(200);
        return pageResult;
    }
    /**
     * 通过id查询对应的课程审核信息
     * @param id 要查询的课程核查信息id
     */
    @RequestMapping("/advanced/getauditbyid")
    public PageResult getAll(int page, int limit,int id) {
        log.info("查询课程审核信息");
        Map<String, Object> map = new HashMap<>();
        PageHelper.startPage(page, limit);
        List<CourseAudit> list = courseAuitService.findAuditById(id);
        PageInfo<CourseAudit> pageInfo = new PageInfo<>(list);
        log.info("查询课程审核信息成功");
        PageResult pageResult=new PageResult();
        pageResult.setState(0);
        pageResult.setMessage("成功");
        pageResult.setTotal(pageInfo.getTotal());
        pageResult.setData(pageInfo.getList());
        return pageResult;
    }
}
